home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / rexx / modname.rexx < prev    next >
OS/2 REXX Batch file  |  1993-04-11  |  4KB  |  130 lines

  1. /* A mod. reader
  2.  *
  3.  *   By, James Atwill
  4.  *
  5.  *  Works with most standard MOD. formats.
  6.  *
  7.  * Will Identify David Whittaker modules (kind of).
  8.  * Recognizes, but doesn't parse MED modules. (Will tell Module Type)
  9.  * Works with NoiseTracker modules.
  10.  * Works with ProTracker Modules.
  11.  * Will Identify name, but not tracks / samples of Old SoundTracker Modules.
  12.  * Will Identify name and author of FTM mods.
  13.  * Works on XPK mods. Displays type and uncompressed size in []'s.
  14.  * Automatically add filecomments to module. (Use: rx ModNAme <filename> F)
  15.  * List Sample Names. (Use: rx ModNAme <filename> V)
  16.  *        (To use both: rx ModName <filename> VF)
  17.  *
  18.  */
  19.  
  20. parse arg modname verb
  21. verb=strip(upper(verb),'B')
  22. if pos('V',verb)>0 then verbose=1
  23. else verbose=0
  24.  
  25. fcomment=0
  26. if pos('F',verb)>0 then fcomment=1
  27.  
  28. if ~exists(modname) then exit 5
  29. call open('fp',modname,'r')
  30. txt=readch('fp',20)
  31.  
  32. modfilename=modname
  33.  
  34. DidXPK=0
  35.  
  36. if left(txt,4)="XPKF" then do
  37.      siz=substr(txt,13,4)
  38.      XPKorigsize=c2d(siz)
  39.      XPKtype=upper(strip(substr(txt,9,4),'B'))
  40.      call close('fp')
  41.      call rename(modname,modname||".1")
  42.      ADDRESS "COMMAND" 'xpack >NIL: FILE='||modname||'.1 SUFFIX=.1'
  43.      DidXPK=1
  44.      call open('fp',modname,'R')
  45.      txt=readch('fp',20)
  46. End
  47.  
  48. OutText="Unknown Mod Format"
  49.  
  50. /* Is it?  I looked at a few, and they all started with this.. */
  51. if left(txt,5)="Hgq~a" then do
  52.      outtext="David Whittaker Module"
  53.      call DoExit
  54.      End
  55.  
  56. if left(txt,3)="MMD" then do
  57.      if substr(txt,4,1)="0" then do
  58.           outtext="Old Style MED Module"
  59.           call DoExit
  60.      End
  61.      if Substr(txt,4,1)="1" then do
  62.           outtext="New Style MED Module"
  63.           call DoExit
  64.      End
  65.      outtext="MED Module - Unknown Version"
  66.      call DoExit
  67. End
  68.  
  69. If left(txt,4)="FTMN" then do
  70.      tit=strip(substr(txt,17,100),'B')
  71.      txt2=readch('fp',28)
  72.      tit=tit||txt2
  73.      tit=strip(tit,'B')
  74.      aut=strip(readch('fp',29),'B')
  75.      tit=strip(compress(tit,'0'x),'B')
  76.      aut=strip(compress(aut,'0'x),'B')
  77.      outtext="FTM: Title: "||tit||"  Author: "||aut
  78.      call DoExit
  79. end
  80.      
  81. txt=strip(compress(txt,'0'x),'B')
  82. modname=txt
  83. samples=0
  84. do i = 1 to 31
  85.      txt=readch('fp',22)
  86.      txt=strip(compress(txt,'0'x),'B')  /* Trim padding NULs */
  87.      if left(txt,1)='f0'x then do
  88.           outtext= "Name: `"||modname||"' -> Old SoundTracker Module."
  89.           call DoExit
  90.      End
  91.      txt=left(txt,22)
  92.      len=readch('fp',2)
  93.      x=readch('fp',6) /* FineTune, Volume, RepeatRate, Repeat Length */
  94.      len2=c2d(len)
  95.      len2=len2*2    /* Stored in WORDs */
  96.      if len2>0 then do
  97.  
  98.  
  99.           if verbose then say "Sample #"||right(i,2)||": "||txt||"    Bytes: "||len2
  100.           samples=samples+1
  101.      End
  102. End
  103. part2:
  104. len=c2d(readch('fp',1))  /* Song Length, 1-128 */
  105. x=readch('fp',129) /* '127', Song positions, IDCode. */
  106. if samples=0 | len=0 then call DoExit
  107. outtext= "Name: "||modname||" Samps: "||left(samples,3)||" Trks: "||len
  108. call close('fp')
  109.  
  110. DoExit:
  111.      call close('fp')
  112.      if DidXPK=1 then do
  113.           call delete(modfilename)
  114.           call rename(modfilename||".1",modfilename)
  115.           outtext="["||XPKtype||" "||XPKorigsize||"] "||outtext
  116.           End
  117.      if fcomment=1 then do
  118.           pout=""
  119.           do i = 1 to length(outtext)
  120.                x=substr(outtext,i,1)
  121.                if x='"' then x='*"'
  122.                pout=pout||x
  123.                End
  124.           cmd=""
  125.           cmd='filenote '||modfilename||' "'||pout||'"'
  126.           ADDRESS "COMMAND" cmd
  127.      End
  128.      say outtext
  129. exit
  130.